/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * page1.java
 *
 * Created on 09-dic-2008, 15:52:10
 */

package dbapplication.UI;

import dbapplication.Integracion.*;
/**
 *
 * @author Administrador
 */
public class Page1 extends javax.swing.JFrame {

    /** Creates new form page1 */
    public Page1() {
        initComponents();
        this.setSize(480,450);
        this.setLocation(450, 200);
//        this.setIconImage(
//                new javax.swing.ImageIcon(getClass().getResource("/UI/Imagenes/Icono_ventana.png")).getImage() );

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jLabelMensaje = new javax.swing.JLabel();
        jButtonOK = new javax.swing.JButton();
        jLabelTipoUsuario = new javax.swing.JLabel();
        jComboBoxTipoUsuario = new javax.swing.JComboBox();
        jButtonIniciar = new javax.swing.JButton();
        jLabelTitulo = new javax.swing.JLabel();
        jLabelTitulo2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabelContraseña = new javax.swing.JLabel();
        jPassword = new javax.swing.JPasswordField();

        jDialog1.setVisible(false);

        jLabelMensaje.setText("Contraseña Incorrecta!!!!");

        jButtonOK.setText("OK");
        jButtonOK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonOKMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog1Layout.createSequentialGroup()
                .addContainerGap(102, Short.MAX_VALUE)
                .addComponent(jButtonOK)
                .addGap(99, 99, 99))
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addComponent(jLabelMensaje)
                .addContainerGap(63, Short.MAX_VALUE))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabelMensaje)
                .addGap(29, 29, 29)
                .addComponent(jButtonOK)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelTipoUsuario.setText("Tipo de Usuario:");

        jComboBoxTipoUsuario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione el Usuario", "Administrador", "Empleado", "Cliente" }));
        jComboBoxTipoUsuario.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxTipoUsuarioItemStateChanged(evt);
            }
        });

        jButtonIniciar.setText("Iciciar");
        jButtonIniciar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonIniciarMouseClicked(evt);
            }
        });

        jLabelTitulo.setText("NOMBRE DE LA AGENCIA DATA BASE.....xs");

        jLabelTitulo2.setText("DIBUJITO xS");

        jLabelContraseña.setText("Contraseña:");
        jLabelContraseña.setVisible(false);

        jPassword.setText("jPasswordField1");
        jPassword.setVisible(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabelContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabelContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(172, Short.MAX_VALUE)
                .addComponent(jButtonIniciar)
                .addGap(173, 173, 173))
            .addGroup(layout.createSequentialGroup()
                .addGap(102, 102, 102)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelTitulo, javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabelTitulo2, javax.swing.GroupLayout.Alignment.CENTER))
                .addGap(68, 68, 68))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(94, 94, 94)
                .addComponent(jLabelTipoUsuario)
                .addGap(32, 32, 32)
                .addComponent(jComboBoxTipoUsuario, 0, 126, Short.MAX_VALUE)
                .addGap(76, 76, 76))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(jLabelTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelTitulo2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTipoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxTipoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonIniciar)
                .addGap(47, 47, 47))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonIniciarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonIniciarMouseClicked
       
       String tipo = (String)jComboBoxTipoUsuario.getSelectedItem();
        
       if(tipo.equals("Administrador"))
          if( !Controlador.isAministrador(tipo,jPassword.getText())                    )
               jDialog1.setVisible(true);
       else
          {
              Page2 v = new Page2(tipo);
              v.setVisible(true);
          }
}//GEN-LAST:event_jButtonIniciarMouseClicked

    private void jButtonOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOKMouseClicked
        jDialog1.setVisible(false);
        jPassword.setText("");
    }//GEN-LAST:event_jButtonOKMouseClicked

    private void jComboBoxTipoUsuarioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxTipoUsuarioItemStateChanged
       if(jComboBoxTipoUsuario.getSelectedItem().equals("Administrador"))
       {
           jLabelContraseña.setVisible(true);
           jPassword.setVisible(true);
       }
       else
       {
           jLabelContraseña.setVisible(false);
           jPassword.setVisible(false);
       }

    }//GEN-LAST:event_jComboBoxTipoUsuarioItemStateChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Page1().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonIniciar;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JComboBox jComboBoxTipoUsuario;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JLabel jLabelContraseña;
    private javax.swing.JLabel jLabelMensaje;
    private javax.swing.JLabel jLabelTipoUsuario;
    private javax.swing.JLabel jLabelTitulo;
    private javax.swing.JLabel jLabelTitulo2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPassword;
    // End of variables declaration//GEN-END:variables

}
